#!/usr/bin/python -S
"""
cre_compile_test.py: Tests for cre_compile.py
"""

import unittest

import cre_compile  # module under test


class CreCompileTest(unittest.TestCase):

  def setUp(self):
    pass

  def tearDown(self):
    pass

  def testCompileDefs(self):
    #print cre_compile.CompileDefs(['Literal', 'a'])

    r = cre_compile.Regex('Start = &space+')
    r = cre_compile.Regex('Start = digit*')

    r = cre_compile.Regex('Start = {whitespace?}')

    r = cre_compile.Regex(r'Start = "abcd [] () {} \\"')

    r = cre_compile.Regex(r'Start = "a" "b"')
    r = cre_compile.Regex(r'Start = either "\r" or "\n"')

    r = cre_compile.Regex(r'Start = %begin "a" %end %boundary')

    r = cre_compile.Regex("""
       Start = Three Three Four
       Three = digit*
       Four = wordchar*   # TODO: change to digit^4
    """)

    r = cre_compile.Regex('Start = any+')

    r = cre_compile.Regex('Start = chars[a-z 0-9]')
    r = cre_compile.Regex('Start = !chars[a-z]')

    r = cre_compile.Regex('Start = !chars[a-z]^(3..5)')
    r = cre_compile.Regex('Start = !chars[a b c]^3')

    r = cre_compile.Regex('Start = ("a" "b")*')

    r = cre_compile.Regex('Start = !%ASSERT(wordchar)')

    r = cre_compile.Regex("{ 'a' } REF(1) ")
    r = cre_compile.Regex("{ 'a' as foo } REF(foo) ")
    print r.to_py()

    # What about REF(word) -- that's taken as a keyword?  You need a good
    # syntax error if someone tries to call a group 'word', which is likely.
    r = cre_compile.Regex('Start = {wordchar+ as foo} REF(foo)')

    r = cre_compile.Regex("""
flags(multiline ignorecase)

Start = wordchar+
""")


if __name__ == '__main__':
  unittest.main()
